package com.dcy.seatastorage.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dcy.common.annotation.Log;
import com.dcy.common.model.PageModel;
import com.dcy.common.model.R;
import com.dcy.common.model.PageResult;
import com.dcy.seatastorage.biz.dto.input.StorageTblCreateInputDTO;
import com.dcy.seatastorage.biz.dto.input.StorageTblSearchInputDTO;
import com.dcy.seatastorage.biz.dto.input.StorageTblUpdateInputDTO;
import com.dcy.seatastorage.biz.dto.output.StorageTblListOutputDTO;
import com.dcy.seatastorage.biz.dtomapper.MStorageTblMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import com.dcy.seatastorage.api.model.StorageTbl;
import com.dcy.seatastorage.biz.service.StorageTblService;
import org.springframework.web.bind.annotation.*;
import com.dcy.db.base.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author dcy
 * @since 2021-04-23
 */
@RestController
@RequestMapping("/storage-tbl")
@Api(value = "StorageTblController", tags = {"操作接口"})
public class StorageTblController extends BaseController<StorageTblService, StorageTbl> {

    @Autowired
    private MStorageTblMapper mStorageTblMapper;

    @Log
    @ApiOperation(value = "字典类型分页查询")
    @GetMapping("/page")
    public R<PageResult<StorageTblListOutputDTO>> pageList(StorageTblSearchInputDTO storageTblSearchInputDTO, PageModel pageModel) {
        // 转换model
        StorageTbl storageTbl = mStorageTblMapper.toStorageTbl(storageTblSearchInputDTO);
        // 获取源对象
        IPage<StorageTbl> pageListByListInputDTO = baseService.pageListByEntity(storageTbl, pageModel);
        // 转换新对象
        List<StorageTblListOutputDTO> storageTblListOutputDTOS = mStorageTblMapper.toList(pageListByListInputDTO.getRecords());
        // 返回业务分页数据
        return success(toPageDTO(pageListByListInputDTO, storageTblListOutputDTOS));
    }

    @Log
    @ApiOperation(value = "添加")
    @PostMapping("/save")
    public R<Boolean> save(@ApiParam @RequestBody StorageTblCreateInputDTO storageTblCreateInputDTO) {
        StorageTbl storageTbl = mStorageTblMapper.toStorageTbl(storageTblCreateInputDTO);
        return super.save(storageTbl);
    }

    @Log
    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public R<Boolean> update(@ApiParam @RequestBody StorageTblUpdateInputDTO storageTblUpdateInputDTO) {
        StorageTbl storageTbl = mStorageTblMapper.toStorageTbl(storageTblUpdateInputDTO);
        return super.update(storageTbl);
    }

    @Log
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true)
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@RequestParam String id) {
        return super.delete(id);
    }

    @Log
    @ApiOperation(value = "根据list删除")
    @PostMapping(value = "/deleteBatch")
    public R<Boolean> deleteBatch(@ApiParam @RequestBody List<String> idList) {
        return super.deleteBatch(idList);
    }

}
